 <?php
 session_start();
require('classes/fpdf/fpdf.php');
include('config.php');
require('classes/class.jira.php');
include("classes/connect.php");
ini_set('display_errors', 'Off');

if(isset($_GET["vcode"])){
	$vcode=$_GET["vcode"];
}
$sql1="SELECT * from trn_emaildetails where vcode='".$vcode."'";
$rs1 =mysql_query($sql1);
$row = mysql_fetch_array($rs1);
$config->username= $username;
$config->password= $pass;
$config->port= "";
$config->host= $host;
$queryComment=new Jira($config);
$commentarray=$queryComment->queryComment($row['jiraTaskID']);
$commentresponse1=json_decode($commentarray->responseBody);

$query->key=$row['jiraTaskID'];
$queryrefer=new Jira($config);
$queryrefer1=$queryrefer->queryIssue($query);
$queryrefer2=json_decode($queryrefer1->responseBody);

//create a FPDF object
$pdf=new FPDF();

//set document properties
$pdf->SetAuthor('Lana Kovacevic');
$pdf->SetTitle('FPDF tutorial');

//set font for the entire document
$pdf->SetFont('Helvetica','B',20);

//set up a page
$pdf->AddPage('P');

//config
$r=172;
$g=176;
$b=174;

//display the title with a border around it
$pdf->SetXY(5,20);
$pdf->SetFillColor($r,$g,$b);
$pdf->Cell(200,10,$row['applicantName'],1,0,'C',1);

$dbname=array('fname','lname','address1','address2','city','birthday','school','highschool','highprofessional','currentSalary','expectedsalary','howsoon','whyhire');
$pdfname=array('First name','Last name','address1','address2','City','Birthday','School','Institute (School/University)','Highest Professional Qualification','Current Salary','Expected Salary','How soon can you join','Why we should hire you');
//Set x and y position for the main text, reduce font size and write content
$x=10;
$y=30;
for($i=0;count($dbname)>$i;$i++){
	
	$pdf->SetXY ($x,$y);
	$pdf->SetFontSize(10);
	$pdf->Cell(100,10,$pdfname[$i]);
	$pdf->SetXY ($x+80,$y);
	$pdf->Cell(100,10,': '.$row[$dbname[$i]]);
	$y=$y+10;	
}
$sql2="SELECT * from trn_projectexperience where mainid='".$row['id']."'";
$rs2 =mysql_query($sql2);
if(mysql_num_rows($rs2)>0){
$pdf->SetXY ($x,$y);
$y=$y+10;
$pdf->SetFontSize(10);
$pdf->SetFillColor($r,$g,$b);
$pdf->Cell(190,10,'Hands On Experience',1,0,'C',1);
$i=1;
	while($row1 = mysql_fetch_array($rs2)){
		
		$pdf->Ln();
		$pdf->SetFontSize(12);
		$pdf->Cell(60,10,'Project/Work Experience '.$i);
		$pdf->Ln();
		$pdf->SetFontSize(10);
		$pdf->Multicell(200,5,$row1['experince'],0,L);
		$y=$y+10;
		$i++;
	}
}
$pdf->Ln();
$pdf->SetFontSize(10);
$pdf->SetFillColor($r,$g,$b);
$pdf->Cell(190,10,'Technologies Known',1,0,'C',1);
$pdf->Ln();

$sql3="SELECT * from trn_technologyskills where mainid='".$row['id']."'";
$rs3 =mysql_query($sql3);
while($row2 = mysql_fetch_array($rs3)){
	$sql4="SELECT * from sys_technicalskills where id='".$row2['techid']."'";
	$rs4 =mysql_query($sql4);
	$row3 = mysql_fetch_array($rs4);

	$pdf->Cell(20,10,$row3['skillname']);
}

$sqlquery="SELECT * from trn_workexperience where mainid='".$row['id']."'";
$result=mysql_query($sqlquery);
if(mysql_num_rows($result)>0){	
$pdf->Ln();
$pdf->SetFontSize(10);
$pdf->SetFillColor($r,$g,$b);
$pdf->Cell(190,10,'Current Workplace',1,0,'C',1);

$sql5="SELECT * from trn_workexperience where mainid='".$row['id']."' AND currentplace = '1'";
$rs5 =mysql_query($sql5);
$row4 = mysql_fetch_array($rs5);
	$pdf->Ln();
	$pdf->SetFontSize(12);
	$pdf->Cell(60,10,'Designation ');
	$pdf->SetFontSize(10);
	$pdf->Cell(100,10,$row4['designation']);
	
	$pdf->Ln();
	$pdf->SetFontSize(12);
	$pdf->Cell(60,10,'Company');
	$pdf->SetFontSize(10);
	$pdf->Cell(100,10,$row4['companyname']);
	
	$pdf->Ln();
	$pdf->SetFontSize(12);
	$pdf->Cell(60,10,'Join Date ');
	$pdf->SetFontSize(10);
	$pdf->Cell(100,10,$row4['joineddate']);
}	
$sql6="SELECT * from trn_workexperience where mainid='".$row['id']."' AND currentplace = '0'";
$rs6 =mysql_query($sql6);

if(mysql_num_rows($rs6)>0){
$pdf->Ln();
$pdf->SetFontSize(10);
$pdf->SetFillColor($r,$g,$b);
$pdf->Ln();
$pdf->Cell(190,10,'Previous Workplace',1,0,'C',1);
while($row5 = mysql_fetch_array($rs6)){

	$pdf->Ln();
	$pdf->SetFontSize(12);
	$pdf->Cell(60,10,'Designation ');
	$pdf->SetFontSize(10);
	$pdf->Cell(100,10,$row4['designation']);
	
	$pdf->Ln();
	$pdf->SetFontSize(12);
	$pdf->Cell(60,10,'Company');
	$pdf->SetFontSize(10);
	$pdf->Cell(100,10,$row4['companyname']);
	
	$pdf->Ln();
	$pdf->SetFontSize(12);
	$pdf->Cell(60,10,'Join Date ');
	$pdf->SetFontSize(10);
	$pdf->Cell(100,10,$row4['joineddate']);

}
}
$pdf->Ln();
$pdf->SetFontSize(10);
$pdf->SetFillColor($r,$g,$b);
$pdf->Ln();
$pdf->Cell(190,10,'JIRA Comments',1,0,'C',1);
$pdf->Ln();


if(!empty($commentresponse1->comments)){
	foreach($commentresponse1->comments as $value){
		$pdf->Ln();
		$pdf->SetFontSize(10);
		$pdf->Multicell(200,5,$value->body,0,L);
		
	}
}
else{
		$pdf->Ln();
		$pdf->SetFontSize(10);
		$pdf->Multicell(200,5,'No Comments recorded in JIRA',0,L);
}

//Output the document
$pdf->Output($queryrefer2->issues[0]->key.' - '.$row['post'].' - '.$row['applicantName'].'.pdf','D');
?> 